<?php
	date_default_timezone_set('Asia/Shanghai');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo empty($_GET['name']) ? '某人' : $_GET['name']; ?>的生命倒计时</title>
<style>
body {
	background:#000000;
	color:#FFFF33;
	font-family:"微软雅黑";
	margin:0;
	font-size:12px;
}
.top {
	color:#999;
	text-align:right;
	font-size:12px;
	height:18px;
	word-spacing:5px;
	padding:4px 10px 0 0;
	font-family:Arial, Helvetica, sans-serif;
	background:#333;
	border-bottom:#444 1px solid;
}
.top a {
	color:#999;
	text-decoration:none;
}
.lifetimer {
	font-size:50px;
	text-align:center;
	margin:150px 0 0 0;
}
.lifetimer .timer i {
	font-style:normal;
	font-size:20px;
}
.lifetimerheader {
	font-size:20px;
	margin:10px;
	color:#CCCCCC;
}
.lifetimerfooter {
	font-size:30px;
	margin:10px;
	color:#CCCCCC;
}
</style>
<script>
var Lifetimer = {
	// 出生日期
	birthday : [1987, 09, 24],
	// 寿命年数
	lifetimeYear : 80,
	
	// 出生日期对象
	dateBirth : null,
	// 死亡日期对象
	dateDeath : null,
	
	// 初始化
	init : function() {
	
		this.dateBirth = new Date(this.birthday[0], this.birthday[1] - 1, this.birthday[2]);
		this.dateDeath = new Date(parseInt(this.birthday[0]) + this.lifetimeYear, this.birthday[1] - 1, this.birthday[2] - 1);
			
		var dateDeathString = this.dateDeath.getFullYear() + '年' + (this.dateDeath.getMonth() + 1) + '月' + (this.dateDeath.getDate() + 1) + '日';
		this.get('lifetimerheader').innerHTML = '距您的生命截至日期 ' + dateDeathString + ' 还有';
		
		setInterval('Lifetimer.display()', 10);
	},
	
	// 获取HTML结点
	get : function(id) {
		return document.getElementById(id);
	},
	
	// 显示计时
	display : function(id) {
		var dateNow = new Date();
		var result = this.dateDeath.getTime() - dateNow.getTime();
		
		if(result <= 0) {
			this.get('timer').innerHTML = ';( 抱歉，您已经离开人世！';
			return;
		}
		
		var ms =  result % 1000;
		var s = parseInt(result / 1000) % 60;
		var i = parseInt(result / 60000) % 60;
		var h = parseInt(result / 3600000) % 24;
		var d = parseInt(result / 86400000);
		
		this.get('timer').innerHTML = d + '<i>天</i>' + h + '<i>小时</i>' + i + '<i>分</i>' + s + '<i>秒</i>' + ms + '<i>微秒</i>';
	}
}
</script>

<script>
// 程序入口
<?php $birth = empty($_GET['birth']) ? explode('-', '1987-09-24') : explode('-', $_GET['birth']); ?>
window.onload = function() {
	Lifetimer.birthday = <?php echo json_encode($birth); ?>;
	Lifetimer.lifetimeYear = <?php echo empty($_GET['lifetime']) ? '80' : $_GET['lifetime']; ?>;
	Lifetimer.init();
}
</script>
</head>

<body>

<!-- start.导航栏 -->
<div class="top">
	<?php echo empty($_GET['name']) ? '某人' : $_GET['name']; ?>的生命倒计时
	|
	<a href="create.php">创建</a>
	|
	<span onclick="alert('抱歉，您的生命无法暂停！请购买时光机器！');" style="cursor:pointer;">暂停计时</span>
	|
	<strong><?php echo date('Y-m-d'); ?></strong>
</div>
<!-- end.导航栏 -->

<!-- start.计时器 -->
<div class="lifetimer">
	<div id="lifetimerheader" class="lifetimerheader"></div>
	<div id="timer" class="timer"></div>
	<div id="lifetimerfooter" class="lifetimerfooter"><?php echo empty($_GET['note']) ? '生命倒计时无法暂停！' : $_GET['note'];?></div>
</div>
<!-- end.计时器 -->

</body>
</html>